package com.fastCms.business.frame.utils.opc;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: RogersZheng
 * @Date: 2021/6/15 1:40 下午
 * @Description: com.fastCms.comm.utils
 */
public class DateUtil {

    /**
     * 生成最近的时刻，即分钟是15的倍数
     * <pre> 如
     *  1. 当前9：22,则返回9：15
     *  2. 当前9：23，则返回9：30
     * </pre>
     *
     * @return
     */
    public static Date getRecentMoment() {
        Calendar calendar = Calendar.getInstance();
        BigDecimal minute = BigDecimal.valueOf(calendar.get(Calendar.MINUTE));
        BigDecimal tag = BigDecimal.valueOf(15);
        BigDecimal resultMinute = minute.divide(tag, 0, BigDecimal.ROUND_HALF_UP).multiply(tag);
        calendar.set(Calendar.MINUTE, resultMinute.intValue());
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static String getPassDay(Integer pass) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        Calendar c = Calendar.getInstance();

        //过去九天
        c.setTime(new Date());
        c.add(Calendar.DATE, -pass);
        Date d = c.getTime();
        String day = format.format(d);
        return day;
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getCurrentTime() {
        return DateFmt.formateTime(Calendar.getInstance().getTime());
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getCurrentDay() {
        return DateFmt.formateDay(Calendar.getInstance().getTime());
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getCurrentDayS() {
        return DateFmt.formateDay(Calendar.getInstance().getTime()) + " 00:00:00";
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getPassDayS(Integer pass) {
        Calendar c = Calendar.getInstance();

        //过去九天
        c.setTime(new Date());
        c.add(Calendar.DATE, -pass);
        Date d = c.getTime();

        return DateFmt.formateTime(d);
    }


    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getCurrentDayE() {
        return DateFmt.formateDay(Calendar.getInstance().getTime()) + " 23:59:59";
    }


}
